<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="视频管理">

    <!--suppress ALL -->
        <form id="searchForm" class="form-panel" action="/rest/manage/video/selectVideoManagePage">
            <ul class="panel-content">
                <li>
                    <div class="form-actions">
                        <div class="control-group controls span5">
                            <input type="text" id="searchForm" class="input-normal  input-pad " name="name">
                        </div>
                        <div class="form-actions  controls">
                            <button type="submit" class="button  button-success">
                                查询
                            </button>
                        </div>
                        <div class="form-actions  controls">
                            <a  class="button  button-danger" onclick="addVideo()">
                                新增
                            </a>
                        </div>
                        <div class="form-actions  controls">

                            <a  class="button  button-info" onclick="delFunction()" >
                                删除
                            </a>
                        </div>
                    </div>
                </li>
            </ul>
        </form>
    <div id="grid"></div>
<div id="addContent" style="display:none;">
    <form id="addForm" class="form-horizontal" action="${basepath}/rest/manage/video/insertJson" method="post">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">所属沙场：</label>

                <div class="controls">
                    <select class="input-normal control-text test-select" name="sandpit" id="" data-rules="{required : true}">
                        <option value="马庄">马庄</option>
                        <option value="涂庄">涂庄</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">摄像头名称：</label>
                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="name" data-rules="{required : true}">
                </div>
            </div>
        </div>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">设备地址：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="address" data-rules="{required : true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">视频链接：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="url"
                           data-rules="{required : true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">排序：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="sort"
                           data-rules="{required : true,number:true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">类型：</label>

                <div class="controls">
                    <select class="input-normal control-text test-select" name="sno" data-rules="{required : true}">
                        <option value="1">云台</option>
                        <option value="0">枪机</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<#----------------------------------------------新增表单 end---------------------------------------------------------->
<div id="editContent" style="display:none;">
    <form id="editForm" class="form-horizontal" action="${basepath}/rest/manage/video/updateJson" method="post">
        <input type="hidden" name="id">
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">所属沙场：</label>

                <div class="controls">
                    <select class="input-normal control-text test-select" name="sandpit" id="" data-rules="{required : true}">
                        <option value="马庄">马庄</option>
                        <option value="涂庄">涂庄</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">摄像头名称：</label>
                <div class="control-group-img  controls ">
                    <input type="text" class="input-normal control-text" name="name" data-rules="{required : true}">
                </div>
            </div>
        </div>

        <div class="row">
            <div class="control-group span16">
                <label class="control-label">设备地址：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="address" data-rules="{required : true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">视频链接：</label>
                <div class="controls">
                    <input type="text" class="input-normal control-text" name="url"
                           data-rules="{required : true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">排序：</label>

                <div class="controls">
                    <input type="text" class="input-normal control-text" name="sort"
                           data-rules="{required : true,number:true}">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="control-group span16">
                <label class="control-label">类型：</label>

                <div class="controls">
                    <select class="input-normal control-text test-select" name="sno" data-rules="{required : true}">
                        <option value="1">云台</option>
                        <option value="0">枪机</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
</div>
<script>
    var Grid = BUI.Grid,
            Calendar = BUI.Calendar,
            datepicker = new Calendar.DatePicker({
                trigger:'.calendar-time',
                dateMask :'yyyy-mm-dd HH:MM:ss',
                showTime:true,
                autoRender : true
            }),
            Store = BUI.Data.Store,
            columns = [
                {title : '序号',elCls: 'center',  dataIndex :'index', width:'10%',renderer:function (value, obj, index) {
                        return index+1;
                    }},
                {title : '所属砂场',elCls: 'center',  dataIndex :'sandpit', width:'16%'},
                {title : '摄像头名称',elCls: 'center',  dataIndex :'name', width:'16%'},
                {title : '设备地址',elCls: 'center',  dataIndex :'address', width:'16%'},
                {title : '排序',elCls: 'center',  dataIndex :'sort', width:'10%'},
                {title : '配置链接',elCls: 'center', dataIndex :'url', width:'20%'},
                {title : '操作',elCls: 'center', dataIndex :'id', width:'10%',renderer:function (value) {
                        return  '<a  href="javascript:editById(' + value + ')">编辑  </a>' +
                                '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    }},
            ];

    var store = new Store({
                url : '/rest/manage/video/selectVideoManagePage',
                autoLoad:true, //自动加载数据
                params : { //配置初始请求的参数
                    length : '10'
                },
                pageSize:10,	// 配置分页数目
                root : 'list',
                totalProperty : 'total'
            }),
            grid = new Grid.Grid({
                render:'#grid',
                columns : columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar:{
                    pagingBar:true
                }
            });

    grid.render();
    //查询框
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*--------------------------------删除用户---------------------------------------------*/
    //删除选中的记录
    function delFunction() {
        BUI.Message.Confirm('确认要删除吗？', function () {
            var selections = grid.getSelection();
            var ids = new Array();
            for (var i = 0; i < selections.length; i++) {
                ids[i] = selections[i].id.toString()
            }
            $.ajax({
                type: "POST",
                url: "${basepath}/rest/manage/video/deletesJson",
                dataType: "json",
                data: {
                    ids: ids
                },
                success: function (data) {
                    var obj = new Object();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    //删除单个用户
    function deleteOne(value) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/video/deleteJson',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }

    /*------------------------------------------------新增表单处理start------------------------------------------------*/
    var addForm = new BUI.Form.Form({
        srcNode: '#addForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            addDialog.close();
        }
    }).render();

    var addDialog = new BUI.Overlay.Dialog({
        title: '新增设备',
        width: 500,
        height: 380,
        contentId: 'addContent',
        success: function () {
            if (addForm.isValid()) {
                addForm.submit();
            } else {
                addForm.valid();
            }
        }
    });

    //添加上传图片按钮事件
    function addVideo() {
        addForm.clearErrors();
        addForm.clearFields();
        addDialog.show();
    }

    /*------------------------------------------------新增表单处理 end-------------------------------------------------*/
    /*------------------------------------------------编辑表单处理 start-----------------------------------------------*/
    var editForm = new BUI.Form.Form({
        srcNode: '#editForm',
        submitType: 'ajax',
        callback: function (data) {
            var obj = new Object();
            obj.start = 0; //返回第一页
            store.load(obj);
            editDialog.close();
        }
    });
    editForm.render();

    var editDialog = new BUI.Overlay.Dialog({
        title: '编辑设备',
        width: 500,
        height: 380,
        contentId: 'editContent',
        success: function () {
            if (editForm.isValid()) {
                editForm.submit();
            } else {
                editForm.valid();
            }
        }
    });

    //编辑按钮事件
    function editById(id) {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${basepath}/rest/manage/video/toEditJson",
            data: {id: id},
            success: function (data) {
                var form = $("#editForm")[0];
                BUI.FormHelper.setFields(form, data.data);
                editDialog.show();
            }
        });
    }
</script>

</@page.pageBase>
